<template>
  <div>
    <div class="add" v-if="active == 0" @click="add()">新增</div>
    <eagle-list :tabData="tabData" @initActive="_initActive" @bindData="bindData" :filterParams="filterParams"
      :filterParamsDefaul="filterParamsDefaul" :filterTab="filterTab" allowSearch placeholder="请输入文件名称搜索"
      ref="eaglelist">

      <eagle-cell style="margin-top: 10px" class="card" v-for="(item, index) in list" :key="index">
        <div class="warn_item">
          <div @click="goToDetail(item)">
            <div class="warn_header">
              <div>{{ item.CompanyName }}</div>
            </div>
            <van-row gutter="20" class="dep_sort">
              <van-col span="24">
                <img src="@/assets/Images/AppIcon/icon_list_user.png" alt="" class="icon" />安全管理员：{{ item.EhsManager }}
                {{ item.EHSMobile }}
              </van-col>
            </van-row>
            <van-row gutter="20" class="dep_sort">
              <van-col span="24">
                <img src="@/assets/Images/AppIcon/icon_equ_supplier.png" alt="" class="icon" />主要负责人：{{ item.MainManager
                }} {{ item.MainManagerMobile }}
              </van-col>
            </van-row>
            <van-row gutter="20" class="dep_sort">
              <van-col span="24">
                <img src="@/assets/Images/AppIcon/icon_list_kind.png" alt="" class="icon" />行业：{{
      item.ApplyProfessionName }}
              </van-col>
            </van-row>
            <van-row gutter="20" class="dep_sort">
              <van-col span="24">
                <img src="@/assets/Images/AppIcon/icon_number.png" alt="" class="icon" />单位账号：{{ item.ManagerUserName }}
                {{ item.ManagerMobile }}
              </van-col>
            </van-row>
            <van-row gutter="20" class="dep_sort">
              <van-col span="24">
                <img src="@/assets/Images/AppIcon/icon_list_enterprise.png" alt="" class="icon" />企业地址：{{ item.Address
                }}
              </van-col>
            </van-row>
            <van-row gutter="20" class="dep_sort">
              <van-col span="24">
                <img src="@/assets/Images/AppIcon/icon_list_enterprise.png" alt="" class="icon" />关键风险点：{{
      getRiskPoints(item.RiskPoint) }}

              </van-col>
            </van-row>
          </div>
          <van-divider />
          <div class="item_tool">
            <div class="item_tool_item" @click="goToInLower(item)">
              <img src="@/assets/Images/AppIcon/icon_enter.png" alt="" class="icon" />
              <div class="mr-10">进入该企业</div>
            </div>
            <div class="item_tool_item" @click="del(item)">
              <img src="@/assets/Images/AppIcon/icon_list_delete.png" alt="" class="icon" />
              <div class="mr-10">{{ getDeleteTitle(item.DirectDelete) }}</div>
            </div>
          </div>
        </div>
      </eagle-cell>

    </eagle-list>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: 0,
      list: [],
      filterTab: true,
      // filterParamsDefaul: [{ name: "Status", value: "10" }],
      filterParamsDefaul: [],
      filterParams: [
        {
          name: "Status",
          title: "状态",
          originTitle: "状态",
          dataType: "int",
          data: [
            { text: "不限", value: "" },
            { text: "现行", value: "10" },
            { text: "废止", value: "-1" },
          ],
        },
        {
          name: "AppointmentType",
          title: "类别",
          originTitle: "类别",
          dataType: "string",
          data: [
            { text: "不限", value: "" },
            { text: "安全生产领导小组认命", value: "A" },
            { text: "安全生产管理人员认命", value: "B" },
          ],
        },
      ],
      tabData: [
        {
          title: "安全管理机构人员任命",
          url: "/UserCompany/GetPageData",
          isPage: true,
          params: {
            dataType: "orgCompanyList",
          },
        },
        // {
        //   title: "任命书文件",
        //   url: "/ProjectEntrustedOnlineDoc/GetPageData",
        //   isPage: true,
        //   params: {
        //     dataType: "List",
        //     menuNo: "0201",
        //   },
        // },
      ],
      option1: [
        { text: "不限", value: "" },
        { text: "现行", value: "10" },
        { text: "废止", value: "-1" },
      ],
      option2: [
        { text: "不限", value: "" },
        { text: "安全生产领导小组认命", value: "A" },
        { text: "安全生产管理人员认命", value: "B" },
      ],
      riskPoints: [],

    };
  },
  created() {
    this.$axios.get("/UserCompany/GetRiskPoints", {}).then(res => {
      this.riskPoints = res.data
    })
  },
  mounted() {

  },
  methods: {
    getDeleteTitle(DirectDelete) {
      if (DirectDelete > 0) {
        return "删除该企业"
      } else {
        return "申请删除该企业"
      }
    },
    goToDetail(item) {
      this.$router.push({
        path: "/BaseInfo",
        query: { CompanyCode: item.CompanyCode },
      });
    },
    
    _initActive(active) {
      if (active === 0) {
        this.$refs.eaglelist.changefilterTab(true);
      }
      if (active === 1) {
        this.$refs.eaglelist.changefilterTab(false);
      }
      this.active = active;
    },
    bindData(data) {
      this.list = data;
      console.log(this.list)
    },
    goToEdit(item) {
      this.$router.push({
        path: "/SiteappointmentEdit",
        // name: "SiteappointmentEdit",
        query: { id: item.ID },
      });
    },
    // 新增企业
    add() {
      this.$router.push({
        // name: "SiteappointmentAdd",
        path: "/SubUnitAdd",
        query: { id: 0 },
      });
    },
    /**
     * 删除企业
     * @param {*} item 
     */
    del(item) {
      const _this = this;
      if (item.DirectDelete > 0) {

        this.$dialog
          .confirm({
            title: "询问",
            message: "您确定要删除该企业吗？",
          })
          .then(() => {
            this.$axios
              .get("/UserCompany/DeleteCompanyNo", { params: { id: item.ID } })
              .then((res) => {
                _this.$toast.success("删除企业成功");
                setTimeout(() => {
                  _this.$refs.eaglelist.getList();
                }, 300);
              })
              .catch((err) => {
                console.log("err", err);
              });
          })
          .catch(() => {
            // on cancel
          });
      } else {

      }

    },
    goToInLower(){
      this.$dialog.alert({
        title: "询问",
        message: "程序员开发中",
      })
    },
    //获取 关键风险的 数据
    getRiskPoints(RiskPoint) {
      var value = ""
      if (this.riskPoints) {
        this.riskPoints.forEach(element => {
          if ((RiskPoint & element.ID) > 0) {
            let temp = element.Name + "√"
            console.log(temp)

            value = value + temp + "  "
          }

        });
      }
      return value
    }
  }
};
</script>

<style lang="less" scoped>
.risk {
  background-color: #e8f1f8;

  .info_search {
    padding: 10px;
    border-radius: 5px !important;

    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}

.warn_item {
  /*margin-bottom: 10px;*/
  // padding: 10px 0 10px 10px;
  border-radius: 5px;
  position: relative;
}

.warn_header {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 10px;

  .warn_tag {
    position: absolute;
    right: 0;
    top: 0;
    border-radius: 26.64rem 0 0 26.64rem;
  }
}

.dep_sort {
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}


.item_tool {
  display: flex;
  justify-content: space-between;

  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}

.item_tool_item {
  display: flex;
  align-items: center;
}
</style>
